package com.mars.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author King
 * @create 2020/8/26 15:29
 */
public class JdkProxy implements InvocationHandler {


    private Object target;

    public Object JdkProxy(Object target) {
        this.target = target;
        //获取代理对象
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //TODO 前置操作
        System.out.println("##########before################");
        Object res = method.invoke(target, args);
        System.out.println("##########after################");
        //TODO 后置操作
        return res;
    }


}
